package com.ruoyi.web.controller.train;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.TrainingCadetTeacherNotes;
import com.ruoyi.system.domain.TrainingCadetTeacherNotesCount;
import com.ruoyi.system.service.ITrainingCadetTeacherNotesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 跟师笔记Controller
 *
 * @author dp
 * @date 2023-11-27
 */
@Api(tags = {"跟师笔记"})
@RestController
@RequestMapping("/train/notes")
public class TrainingCadetTeacherNotesController extends BaseController {
    @Autowired
    private ITrainingCadetTeacherNotesService trainingCadetTeacherNotesService;
    @Autowired
    TokenService tokenService;

    /**
     * 查询跟师笔记列表
     */
    @ApiOperation(value = "跟师笔记列表", notes = "查询跟师笔记列表详情", tags = {"跟师笔记管理"})
    //@PreAuthorize("@ss.hasPermi('train:notes:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingCadetTeacherNotes trainingCadetTeacherNotes) {
        startPage();
        List<TrainingCadetTeacherNotes> list = trainingCadetTeacherNotesService.selectTrainingCadetTeacherNotesList(trainingCadetTeacherNotes);
        return getDataTable(list);
    }

    /**
     * 查询跟师笔记合计列表
     */
    @ApiOperation(value = "跟师笔记合计列表", notes = "查询跟师笔记列表详情", tags = {"跟师笔记管理"})
    @GetMapping("/countList")
    public TableDataInfo countList(@RequestParam(value = "submitBegin", required = false) String submitBegin,
                                   @RequestParam(value = "submitEnd", required = false) String submitEnd,
                                   @RequestParam("baseId") String baseId,
                                   @RequestParam("notesStatus") String notesStatus,
                                   @RequestParam(value = "cadetId", required = false) Long cadetId,
                                   @RequestParam(value = "cadetName", required = false) String cadetName

    ) {
        startPage();
        List<TrainingCadetTeacherNotesCount> list = trainingCadetTeacherNotesService.selectTrainingCadetTeacherNotesCount(
                submitBegin, submitEnd, baseId, notesStatus, cadetId, cadetName);
        return getDataTable(list);
    }


    @ApiOperation(value = "跟师笔记列表", notes = "查询跟师笔记列表详情", tags = {"跟师笔记管理"})
    //@PreAuthorize("@ss.hasPermi('train:notes:list')")
    @GetMapping("/getNoteList")
    public TableDataInfo getNoteList(@RequestParam(value = "submitBegin", required = false) String submitBegin,
                                     @RequestParam(value = "submitEnd", required = false) String submitEnd,
                                     @RequestParam("baseId") String baseId,
                                     @RequestParam("cadetId") String cadetId,
                                     @RequestParam("notesStatus") String notesStatus) {
        startPage();
        List<TrainingCadetTeacherNotes> list = trainingCadetTeacherNotesService.getNoteList(submitBegin, submitEnd, baseId, cadetId, notesStatus);
        return getDataTable(list);
    }

    /**
     * 导出跟师笔记列表
     */
    @ApiOperation(value = "跟师笔记列表导出", notes = "导出跟师笔记列表", tags = {"跟师笔记管理"})
    //@PreAuthorize("@ss.hasPermi('train:notes:export')")
    @Log(title = "跟师笔记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainingCadetTeacherNotes trainingCadetTeacherNotes) {
        List<TrainingCadetTeacherNotes> list = trainingCadetTeacherNotesService.selectTrainingCadetTeacherNotesList(trainingCadetTeacherNotes);
        ExcelUtil<TrainingCadetTeacherNotes> util = new ExcelUtil<TrainingCadetTeacherNotes>(TrainingCadetTeacherNotes.class);
        util.exportExcel(response, list, "跟师笔记数据");
    }

    /**
     * 获取跟师笔记详细信息
     */
    @ApiOperation(value = "跟师笔记详细信息", notes = "获取跟师笔记详细信息详情", tags = {"跟师笔记管理"})
    //@PreAuthorize("@ss.hasPermi('train:notes:query')")
    @GetMapping(value = "/{notesId}")
    public AjaxResult getInfo(@PathVariable("notesId") Long notesId) {
        return success(trainingCadetTeacherNotesService.selectTrainingCadetTeacherNotesByNotesId(notesId));
    }

    /**
     * 新增跟师笔记
     */
    @ApiOperation(value = "新增跟师笔记", notes = "新增跟师笔记详情", tags = {"跟师笔记管理"})
    //@PreAuthorize("@ss.hasPermi('train:notes:add')")
    @Log(title = "跟师笔记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(HttpServletRequest request, @RequestBody TrainingCadetTeacherNotes trainingCadetTeacherNotes) {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        trainingCadetTeacherNotesService.completeData(trainingCadetTeacherNotes, userId, 1);
        return toAjax(trainingCadetTeacherNotesService.insertTrainingCadetTeacherNotes(trainingCadetTeacherNotes));
    }

    /**
     * 修改跟师笔记
     */
    @ApiOperation(value = "修改跟师笔记", notes = "修改跟师笔记详情", tags = {"跟师笔记管理"})
    //@PreAuthorize("@ss.hasPermi('train:notes:edit')")
    @Log(title = "跟师笔记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(HttpServletRequest request, @RequestBody TrainingCadetTeacherNotes trainingCadetTeacherNotes) {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        trainingCadetTeacherNotesService.completeData(trainingCadetTeacherNotes, userId, 2);
        return toAjax(trainingCadetTeacherNotesService.updateTrainingCadetTeacherNotes(trainingCadetTeacherNotes));
    }

    /**
     * 删除跟师笔记
     */
    @ApiOperation(value = "删除跟师笔记", notes = "删除跟师笔记详情", tags = {"跟师笔记管理"})
    //@PreAuthorize("@ss.hasPermi('train:notes:remove')")
    @Log(title = "跟师笔记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{notesIds}")
    public AjaxResult remove(@PathVariable Long[] notesIds) {
        return toAjax(trainingCadetTeacherNotesService.deleteTrainingCadetTeacherNotesByNotesIds(notesIds));
    }
}
